From: Hilko Bengen Date: Sat, 3 Jan 2026 14:05:07 +0000 (+0100) Subject: Wait for device name to appearr before mount, mkfs X-Git-Tag: archive/raspbian/1%1.56.2-6+rpi1~1^2~1 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22Program/%22http:/www.example.com/cgi/%22https:/%22Program?a=commitdiff_plain;h=937b3ddcbb39bf8fa93a6f4bb78746df2ecb7a94;p=libguestfs.git Wait for device name to appearr before mount, mkfs Gbp-Pq: Name Wait-for-device-name-to-appearr-before-mount-mkfs.patch --- diff --git a/daemon/mkfs.c b/daemon/mkfs.c index fe2e6781..66c937be 100644 --- a/daemon/mkfs.c +++ b/daemon/mkfs.c @@ -52,6 +52,14 @@ do_mkfs (const char *fstype, const char *device, int blocksize, CLEANUP_FREE char *err = NULL; int extfs = 0; + /* Wait up to 15s for device to appear */ + for (int j=0; i < 150; i++) { + if (!access (device, F_OK)) { + break; + } + usleep(100000); + } + if (fstype_is_extfs (fstype)) extfs = 1; diff --git a/daemon/mount.ml b/daemon/mount.ml index 171bea10..2f74555d 100644 --- a/daemon/mount.ml +++ b/daemon/mount.ml @@ -30,6 +30,18 @@ let mount_vfs options vfs mountable mountpoint = let args = ref [] in + (* Wait up to 15s for device to appear *) + (match mountable.m_type with + | MountableDevice | MountablePath -> + if String.starts_with "/dev/" mountable.m_device then + let i = ref 0 in + while (not (Sys.file_exists mountable.m_device)) && (!i < 150) do + Unix.sleepf 0.1; + i := !i + 1; + done + | _ -> () + ); + (* -o options *) (match options, mountable.m_type with | "", (MountableDevice | MountablePath) -> ()